﻿using System;
using System.Data;
using ltModel;

public partial class ltMan_ads_popupAd : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData(GetId());
        }
    }

    string GetId()
    {
        string id = Request.QueryString["id"];
        if (!Str.IsInt(id))
            id = "1";
        return id;
    }

    void LoadData(string id)
    {
        string sql = "select * from lt_tan where [id]=" + id;
        using (IDataReader dr = SqlHelper.Instance.ExecuteReader(sql))
        {
            if (dr.Read())
            {
                sLink.Text = dr["link"].ToString();
                sText.Text = dr["info"].ToString();
                sShow.SelectedToggleStateIndex = Convert.ToInt32(dr["zt"]);
                sBegin.DbSelectedDate = Str.ParseDbTime(dr["stime"]);
                sEnd.DbSelectedDate = Str.ParseDbTime(dr["etime"]);
            }
        }
    }

    protected void RadSave_Click(object sender, EventArgs e)
    {
        string id = GetId();
        string lk = DataProtector.ToSBC(sLink.Text);
        string zt = sShow.SelectedToggleStateIndex.ToString();
        string st = Str.ParseDbTime(sBegin.SelectedDate).ToString();
        string et = Str.ParseDbTime(sEnd.SelectedDate).ToString();
        string info = DataProtector.ToSBC(sText.Text);
        SqlHelper.Instance.ExecuteNonQuery(string.Format("update lt_tan set link='{0}',zt={1},stime='{2}',etime='{3}',[info]='{4}' where [id]={5}", lk, zt, st, et, info, id));
        infoPanel.AddSuccessInfo("修改成功");
        OperateLog.AddSuccessLog(CurrentUser.user_id, Request.UserHostAddress, "修改弹出窗口");
        LoadData(id);
    }
}